package org.pentaho.di.ui.spoon.navigation;

import org.pentaho.di.core.util.Utils;
import org.pentaho.di.ui.spoon.Spoon;

public abstract class Bundle {

    private Spoon spoon;

    public Bundle(Spoon spoon) {
        super();
        this.spoon = spoon;
    }

    public Spoon getSpoon() {
        return spoon;
    }

    public void setSpoon(Spoon spoon) {
        this.spoon = spoon;
    }

    protected boolean isExpanded(boolean entityExpandStatus) {
        boolean expanded = entityExpandStatus;
        // isFilterEnabled的优先级高些，开启过滤则必须展开
        if (isFilterEnabled()) {
            expanded = true;
        }
        return expanded;
    }

    /**
     * 过滤是否启用 ,启用过滤则展开所有的Tree并且去掉为空的分组
     *
     * @return true 启用; false 停用
     */
    private boolean isFilterEnabled() {
        String filter = this.spoon.selectionFilter.getText();
        if (Utils.isEmpty(filter)) {
            return false;
        }
        return true;
    }

}
